package testtomcat;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6567119349266851840L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		System.out.println("调用doGet方法");
		response.setContentType("text;html;charset=utf-8");
		System.out.println("servlet test success....");
		
		response.setContentType("text/html;charset=utf-8");
		
		System.out.println("Client info: "+request.getRemoteAddr()+":"+request.getRemotePort());
		System.out.println("Request info: "+request.getProtocol().toString());
		//resp.write(fileContent);
		String contentType = request.getHeader("Content-Type");
		contentType = request.getProtocol().toString();
		String xx = ("{"
				+ "\"protocol\":\""+contentType+"\","
				+ "\"name\":\""+request.getParameter("name")+"\","
				+ "\"age\":\""+request.getParameter("age")+"\""
		 + "}");
		try {
			response.getWriter().write(xx);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		System.out.println("调用doPost方法");
		doGet(request, response);
	}
}
